﻿using Core.Framework.Model.Common;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Core.DataAccess.Model
{
    public class ConnactionBuilder
    {

        #region 获取数据库配置

        /// <summary>
        /// 获取数据配置节
        /// </summary>
        /// <param name="isReader">是否是读取</param>
        /// <param name="enumType">数据库类型</param>
        /// <returns></returns>
        public static string GetConnactionValue(bool isReader, string typeName)
        {
            string value = string.Empty;

            switch (typeName)
            {
                case "ProjectEntrepotContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Entrepot);
                    break;
                case "ProjectAppInfoContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_AppInfo);
                    break;
                case "ProjectCommentContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Comment);
                    break;
                case "ProjectInformationContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Information);
                    break;
                case "ProjectLogsContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Logs);
                    break;
                case "ProjectNLPContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_NLP);
                    break;
                case "ProjectOrderContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Order);
                    break;
                case "ProjectSocketContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Queue);
                    break;
                case "ProjectWalletContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Wallet);
                    break;
                case "ProjectContext":
                    value = GetConnactionValue(isReader, DBProjectEnum.Project_Mgt);
                    break;
            }

            return value;
        }

        /// <summary>
        /// 获取数据配置节
        /// </summary>
        /// <param name="isReader">是否是读取</param>
        /// <param name="enumType">数据库类型</param>
        /// <returns></returns>
        static string GetConnactionValue( bool isReader ,DBProjectEnum enumType) 
        {
            string value = string.Empty;

            if (isReader)
                value = GetReaderConnactionValue(enumType);
            else
                value = GetWriterConnactionValue(enumType);

            return value;
        }

        /// <summary>
        /// 获取数据配置节
        /// 读
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns></returns>
        static string GetReaderConnactionValue(DBProjectEnum enumType)
        {
            string value = string.Empty;

            switch (enumType)
            {
                case DBProjectEnum.Project_Mgt:
                    value = CoreStartupHelper.GetConnectionValue("Project_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Wallet:
                    value = CoreStartupHelper.GetConnectionValue("Wallet_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Order:
                    value = CoreStartupHelper.GetConnectionValue("Order_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Queue:
                    value = CoreStartupHelper.GetConnectionValue("Socket_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Logs:
                    value = CoreStartupHelper.GetConnectionValue("Logs_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Information:
                    value = CoreStartupHelper.GetConnectionValue("Information_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Entrepot:
                    value = CoreStartupHelper.GetConnectionValue("Entrepot_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Comment:
                    value = CoreStartupHelper.GetConnectionValue("Comment_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_NLP:
                    value = CoreStartupHelper.GetConnectionValue("NLP_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_AppInfo:
                    value = CoreStartupHelper.GetConnectionValue("AppInfo_SqlServerConnection");
                    break;

                default:
                    throw new Exception("未知数据库配置信息");
            }

            return value;

        }

        /// <summary>
        /// 获取数据配置节
        /// 写
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns></returns>
        static string GetWriterConnactionValue(DBProjectEnum enumType)
        {
            string value = string.Empty;

            switch (enumType)
            {
                case DBProjectEnum.Project_Mgt:
                    value = CoreStartupHelper.GetConnectionValue("Project_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Wallet:
                    value = CoreStartupHelper.GetConnectionValue("Wallet_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Order:
                    value = CoreStartupHelper.GetConnectionValue("Order_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Queue:
                    value = CoreStartupHelper.GetConnectionValue("Socket_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Logs:
                    value = CoreStartupHelper.GetConnectionValue("Logs_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Information:
                    value = CoreStartupHelper.GetConnectionValue("Information_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Entrepot:
                    value = CoreStartupHelper.GetConnectionValue("Entrepot_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_Comment:
                    value = CoreStartupHelper.GetConnectionValue("Comment_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_NLP:
                    value = CoreStartupHelper.GetConnectionValue("NLP_SqlServerConnection");
                    break;

                case DBProjectEnum.Project_AppInfo:
                    value = CoreStartupHelper.GetConnectionValue("AppInfo_SqlServerConnection");
                    break;

                default:
                    throw new Exception("未知数据库配置信息");
            }

            return value;

        }

        #endregion



    }
}
